#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define me(f, x) memset(f, x, sizeof(f))
#define mc(f, g) memcpy(f, g, sizeof(f))
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;
#endif

constexpr int N = 4e5 + 9;
int n, m;
LL a[N], b[N];

#define ls p << 1
#define rs p << 1 | 1
#define md ((l + r) >> 1)

struct SGT {
  LL f[N << 2], g[N << 2];
  LL h[N << 2];

  void up (int p) {
    f[p] = f[ls] + f[rs];
    g[p] = g[ls] + g[rs];
    h[p] = h[ls] + h[rs] + f[ls] * g[rs];
  }

  void flp (int x, int l = 1, int r = m, int p = 1) {
    if (l == r) {
      f[p] ^= 1;
      g[p] ^= b[x];
      h[p] ^= b[x];
      return;
    }
    x <= md ? flp(x, l, md, ls) : flp(x, md + 1, r, rs);
    up(p);
  }

  LL ql (int x) {
    int l = 1, r = m, p = 1;
    LL s = 0;
    while (l < r) {
      if (x >= f[ls]) {
        s += g[ls];
        x -= f[ls];
        l = md + 1;
        p = rs;
      } else {
        r = md;
        p = ls;
      }
    }
    assert(x <= 1);
    return s + x * b[l];
  }

  LL qr (int x) {
    int l = 1, r = m, p = 1;
    LL s = 0;
    while (l < r) {
      if (x >= f[rs]) {
        s += g[rs];
        x -= f[rs];
        r = md;
        p = ls;
      } else {
        l = md + 1;
        p = rs;
      }
    }
    assert(x <= 1);
    return s + x * b[l];
  }

  LL QL (int x) {
    int l = 1, r = m, p = 1;
    LL s = 0;
    while (l < r) {
      if (x >= f[ls]) {
        s += (x + 1) * g[ls] - h[ls];
        x -= f[ls];
        l = md + 1;
        p = rs;
      } else {
        r = md;
        p = ls;
      }
    }
    assert(x <= 1);
    return s + x * b[l];
  }

  LL QR (int x) {
    int l = 1, r = m, p = 1;
    LL s = 0;
    while (l < r) {
      if (x >= f[rs]) {
        x -= f[rs];
        s += h[rs] + x * g[rs];
        r = md;
        p = ls;
      } else {
        l = md + 1;
        p = rs;
      }
    }
    assert(x <= 1);
    return s + x * b[l];
  }
} T;

int main () {
  FIO("kte");
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  L (i, 1, n) {
    cin >> a[i], b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  m = unique(b + 1, b + n + 1) - b - 1;
  L (i, 1, n) {
    a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b;
  }
  L (tt, 1, n) {
    T.flp(a[tt]);
    int K = T.f[1];
    int l = 1, r = (K + 1) / 2;
    while (l < r) {
      if (T.ql(md + 1) >= T.qr(md)) {
        l = md + 1;
      } else {
        r = md;
      }
    }
    LL ans = 0;
    if (K - l >= l) {
      ans += T.qr(K - l) - T.ql(l);
    }
    if (l > 1) {
      ans += (T.QR(l - 1) - T.QL(l - 1)) * 2;
    }
    cout << ans << '\n';
  }
}
// I love WHQ!